package cn.addr.server;


import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class AddrServer {
	private ServerSocket serverSocket = null;

	@SuppressWarnings("unused")
	private ExecutorService executorService = null;

	
	public AddrServer(){
		try {
			executorService = Executors.newFixedThreadPool(Runtime.getRuntime()
					.availableProcessors()*50);
			serverSocket = new ServerSocket(7777);
		} catch (Exception e) {
			e.printStackTrace();
			
		}
	}
	
	public static void main(String[] args) {
//		try {
//			File logfile = new File("log/logs.txt");
//			logfile.createNewFile();
//			System.setOut(new PrintStream(logfile));
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		AddrServer addrServer = new AddrServer();
		addrServer.start();
	}
	

	public void start(){
		try {
			Socket socket = null;
			System.out.println("----正在等待客户端连接----");
			while ((socket = serverSocket.accept()) != null) {
				String ip = socket.getInetAddress().getHostAddress();
				System.out.println("ip地址为" + ip + "的用户正在连接客户端");
				new ObjectServer(socket).start();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
